require(["./config"],function(){
  require(["jquery","loadHF"],function($){
    function Login(){
      this.init();
    }

    Login.prototype.init=function(){
      this.usernameInput = $("#username");
      this.passwordInput = $("#password");
      this.loginBtn = $("#login_botton");
      this.bindEvents();
    }

    Login.prototype.bindEvents=function(){
      this.loginBtn.on("click",()=>{
        let username = this.usernameInput.val(),
          password = this.passwordInput.val();
          //发送ajax请求，登录
          $.ajax({
            url: "http://localhost/etude_project/api/v1/login.php",
            method: "post",
            data: { username, password },
            dataType:"json",
            success: function(data){
             if(data.code === 1){
               alert("登录成功");
               location.href="/index.html";
             }else{
               alert("登录失败");
             }
            }
          })
          return false;
      })
    }
    new Login();
  })
})
